<?php
namespace  Home\Controller;
use Think\Controller;

class AboutController extends Controller {

    private static $adModel;
    private static $adTypeModel;
    private static $columnModel;
    private static $newsModel;
    private static $aboutPic;

    //private static $news;


    public function  __construct()
    {
        parent::__construct();

        if(self::$columnModel==null){
            self::$columnModel=M('column');
        }

        if(self::$adModel==null){
            self::$adModel=M('plug_ad');
        }

        if(self::$adTypeModel==null){
            self::$adTypeModel=M('plug_adtype');
        }
        if(self::$aboutPic==null){
            $adTypeModel=self::$adTypeModel;
            $type['plug_adtype_name'] = "走进七果banner图";
            $adtype = $adTypeModel->where($type)->find()['plug_adtype_id'];

            $adModel = self::$adModel;
            $condition['plug_ad_adtypeid'] = $adtype;
            $condition['plug_ad_checkid'] = 1;
            $condition['plug_ad_open'] = 1;
            $about = $adModel->field('plug_ad_pic')->order('plug_ad_order')->where($condition)->find();
            self::$aboutPic=$about;
        }
        if(self::$newsModel==null){
            self::$newsModel=M('news');
        }
    }


    public function about(){
      //  var_dump($about);
        $this->assign('about', self::$aboutPic);
        $columnModel=self::$columnModel;
        $condition3['column_name']= '走进七果';
        $condition3['column_type']= 1;
        $condition3['column_open']= 1;
        $column_leftid=$columnModel->where($condition3)->getField('c_id');
        $condition2['column_leftid']=$column_leftid;
        $condition2['column_open']=1;
        $columns1=$columnModel->where($condition2)->order('column_order')->Field('c_id,column_name,column_content')->select();

        foreach($columns1 as $key=>$value){
            $columns1[$key]['parent']='走进七果';
            $columns1[$key]['column_content']=html_entity_decode($value['column_content']);
        }
        $this->assign('columns1', $columns1);

        $condition4['column_name']= '产品分类';
        $condition4['column_type']= 1;
        $condition4['column_open']= 1;
        $column_leftid=$columnModel->where($condition4)->getField('c_id');
        $condition5['column_open']= 1;
        $condition5['column_type']= 3;
        $condition5['column_leftid']=$column_leftid;
        $columns2=$columnModel->where($condition5)->order('column_order')->Field('c_id,column_name')->select();
        $this->assign('columns2', $columns2);
        $this->display();
    }


   //走进七果
    function other(){

        $column_name=trim(htmlspecialchars($_POST['name']));
        $columnModel=self::$columnModel;
        //$condition=array();
        $condition['column_name']=$column_name;
        $condition['column_open']=1;
        $columns3=$columnModel->where($condition)->find();
        $columns3['column_content']=html_entity_decode($columns3['column_content']);
        $columns3=json_encode($columns3);
        // echo 1;exit;
       // $columns3=['1',2,3,45];
        echo $columns3;
       // var_dump($columns3);


    }


    //产品分类
    function other2(){
        //创建数据函数对象

        $columnModel=self::$columnModel;
        $newsModel=self::$newsModel;
        $column_name=trim(htmlspecialchars($_POST['name']));
        $condition['column_name']=$column_name;
        $condition['column_open']=1;
        $c_id=$columnModel->where($condition)->find()['c_id'];

        $condition1['news_back']=0;
        $condition1['news_open']=1;
        $condition1['news_columnid']=$c_id;
       // echo $c_id;exit;
        $contents=$newsModel->where($condition1)->field('n_id,news_img,news_title')->order(' `news_time` desc')->select();

       // self::$news =$newsModel->where($condition1)->order(' `news_time` desc')->select();
        $contents=json_encode($contents);
        echo $contents;
    }


    function detail(){
        $newsModel=self::$newsModel;
        $c_id=htmlspecialchars($_POST['id'])?htmlspecialchars($_POST['id']):0;
        //echo $c_id;  exit;
        $condition2['news_back']=0;
        $condition2['news_open']=1;
        $condition2['n_id']=$c_id;
        $news=$newsModel->where($condition2)->find();
        //echo $news['news_columnid'];exit;

        $columnModel=self::$columnModel;
        $news_typename=$columnModel->where('c_id='.$news['news_columnid'])->find()['column_name'];
        $news['news_typename']=$news_typename;
        $news['news_content']=html_entity_decode($news['news_content']);
        $news=json_encode($news);
        echo $news;

    }


    function load(){

        $page=htmlspecialchars($_POST['page']);
        $news_columnid=htmlspecialchars($_POST['key']);
        $newsModel=self::$newsModel;
        $condition="";
        $condition["news_columnid"]=$news_columnid;
        $count =$newsModel->where($condition)->count();
        $pages=ceil($count/2);
        //其中2为步距
        $firstRow=2*$page-1;
        $listRows=2*$page;
        $arrnews=$newsModel->where($condition)->field('n_id,news_img,news_title')->limit($firstRow.",".$listRows)->select();
        $contents=json_encode($arrnews);
        echo $contents;

    }





}